package com.source.multithread.cyclicbarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author wengqy
 * @Date 2020/12/24
 */
public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(5,()->{ System.out.println("召唤神龙成功"); });

        for (int i = 1; i <=5 ; i++) {
            final int temp =i;
            new Thread(()->{

                System.out.println(Thread.currentThread().getName()+"---Thread---"+temp);
                try {
                    Thread.sleep(100);
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },Integer.toString(temp)).start();
        }
    }
}
